package airthmetic.exercise.tree;

import java.util.ArrayList;
import java.util.List;

public class _590_N叉树的后序遍历 {
    public List<Integer> postorder(Node root) {
        if(root == null){
            return new ArrayList<Integer>();
        }
        List<Integer> list = new ArrayList<Integer>();
        recur(root,list);
        return list;
    }

    public void recur(Node node,List<Integer> list){
        if(node == null || node.children == null){
            return;
        }

        for(Node n : node.children){
            recur(n,list);
        }
        list.add(node.val);
    }
}
